http = require 'http'
sys = require 'sys'
target = 'drupal'
connection = http.createClient 80, 'search.twitter.com'
since = 10
getTweets = (connection, target, since) ->
	request = connection.request 'GET', "/search.json?q=#{target}&since_id=#{since}",
		"host": "search.twitter.com"
		"User-Agent": "NodeJS HTTP Client"
	request.addListener 'response',(response) ->
		responseBody = ''
		response.addListener 'data',(chunk) ->
			responseBody += chunk
		response.addListener 'end',() ->
			tweets = JSON.parse responseBody
			results = tweets['results']
			printTweet = (tweet) ->
				"From #{tweet.from_user} : #{tweet.text}\n\n"
			sys.print (printTweet tweet for tweet in results)
	request.end()
setTimeout (getTweets connection, target, 0), 1000
